package com.imut.iot;


//线性队列，好的做法是循环队列
public class AQueue {
	
	//哨兵，p是队首, q是队尾
	
	private int p;
	private int q;
	
	private int[] buf;
	
	
	public AQueue(int length) {
		p=0;
		q=0;
		
		this.buf = new int[length];
	}
	
	
	public void push(int i) {
		if(q==this.buf.length-1) {
		
			p=q=0;
			return;
		}
		this.buf[q++]=i;
	}
	
	
	public int pop() {
		if(p==q) {
			return -1;
		}
		
		return this.buf[p++];
	}
	
	public boolean isEmpty() {
		return p==q;
	}

}
